package models.mes

import slick.basic.DatabaseConfig
import slick.jdbc.JdbcProfile

import java.sql.Timestamp


case class MesProductOrdersRec(
                                rowid: String, //Column(String, nullable=True, primary_key=True, unique=True, index=True)  # 36
                                mo: String, // = Column(String)
                                fentity: Int, // = Column(Integer)
                                mo_item: String, //= Column(String)
                                mo_status: String, //= Column(String)  # A:正常 B：作废 C：审核 D：未审核
                                mo_date: Timestamp, //= Column(DateTime)
                                mo_modify: Timestamp, //= Column(DateTime, nullable=True)
                                mo_approve: Timestamp, //= Column(DateTime, nullable=True)
                                status: String, //= Column(String)  # FStatus: 2:计划确认, 3:下达, 4:开工
                                mo_send: Int, //= Column(SmallInteger)  # 默认0，1：已发送，-1：异常
                                ppbom: String, //= Column(String, nullable=True)
                                ppbom_status: String, //= Column(String, nullable=True)
                                ppbom_approve: Timestamp, // = Column(DateTime, nullable=True)
                                ppbom_send: Int, // = Column(SmallInteger)  # 默认0，1：已发送，-1：异常
                                mo_result: String, //  = Column(Text, nullable=True)
                                ppbom_result: String, // = Column(Text, nullable=True)
                                fid: Int, // = Column(Integer)
                              )

case class MesStockOrdersRec(
                              code: String, // = Column(String, nullable=True, primary_key=True,unique=True, index=True,)  # 36
                              otype: String, // = Column(String)
                              date: Timestamp, // = Column(DateTime)
                              modify: Timestamp, // = Column(DateTime, nullable=True)
                              approve: Option[Timestamp], // = Column(DateTime, nullable=True)
                              status: String, // = Column(String)
                              send: Int, //= Column(SmallInteger)  # 默认0，1：已发送，-1：异常
                              result: String, // = Column(Text, nullable=True)
                              fid: Int, //= Column(Integer)
                            )


protected trait MesOrdersTableTrait {
  val dc = DatabaseConfig.forConfig[JdbcProfile]("slick.dbs.default")

  import dc.profile.api._

  protected class MesProductOrdersRecTable(tag: Tag)
    extends Table[MesProductOrdersRec](tag, "KD2MES_PROD_ORDERS") {
    def rowid = column[String]("ROW_ID",O.PrimaryKey)

    def mo = column[String]("MO") //: String, // = Column(String)

    def fentity = column[Int]("FENTITY") //: Int, // = Column(Integer)

    def mo_item = column[String]("MO_ITEM") //: String, //= Column(String)

    def mo_status = column[String]("MO_STATUS") //: String, //= Column(String)  # A:正常 B：作废 C：审核 D：未审核

    def mo_date = column[Timestamp]("MO_DATE") //: Timestamp, //= Column(DateTime)

    def mo_modify = column[Timestamp]("MO_MODIFY") //: Timestamp, //= Column(DateTime, nullable=True)

    def mo_approve = column[Timestamp]("MO_APPROVE") //: Timestamp, //= Column(DateTime, nullable=True)

    def status = column[String]("STATUS") //: String, //= Column(String)  # FStatus: 2:计划确认, 3:下达, 4:开工

    def mo_send = column[Int]("MO_SEND") //: String, //= Column(SmallInteger)  # 默认0，1：已发送，-1：异常

    def ppbom = column[String]("PPBOM") //: String, //= Column(String, nullable=True)

    def ppbom_status = column[String]("PPBOM_STATUS") //: String, //= Column(String, nullable=True)

    def ppbom_approve = column[Timestamp]("PPBOM_APPROVE") //: Timestamp, // = Column(DateTime, nullable=True)

    def ppbom_send = column[Int]("PPBOM_SEND") //: Int, // = Column(SmallInteger)  # 默认0，1：已发送，-1：异常

    def mo_result = column[String]("MO_RESULT") //: String, //  = Column(Text, nullable=True)

    def ppbom_result = column[String]("PPBOM_RESULT") //: String, // = Column(Text, nullable=True)

    def fid = column[Int]("FID") //: Int, // = Column(Integer)

    def * =
      (rowid, mo, fentity, mo_item, mo_status, mo_date, mo_modify, mo_approve, status, mo_send,
        ppbom, ppbom_status, ppbom_approve, ppbom_send, mo_result, ppbom_result, fid)
        .<>((MesProductOrdersRec.apply _).tupled, MesProductOrdersRec.unapply)
  }

  protected class MesStockOrdersRecTable(tag: Tag)
    extends Table[MesStockOrdersRec](tag, "KD2MES_STOCK_ORDERS") {
    def code = column[String]("CODE",O.PrimaryKey) //: String, // = Column(String, nullable=True, primary_key=True,unique=True, index=True,)  # 36

    def otype = column[String]("OTYPE") //: String, // = Column(String)

    def date = column[Timestamp]("FDATE") //: Timestamp, // = Column(DateTime)

    def modify = column[Timestamp]("MODIFY_DATE") //: Timestamp, // = Column(DateTime, nullable=True)

    def approve = column[Option[Timestamp]]("APPROVE_DATE") //: Timestamp, // = Column(DateTime, nullable=True)

    def status = column[String]("STATUS") //: String, // = Column(String)

    def send = column[Int]("SEND") //: Int, //= Column(SmallInteger)  # 默认0，1：已发送，-1：异常

    def result = column[String]("RESULT") //: String, // = Column(Text, nullable=True)

    def fid = column[Int]("FID") //: Int, //= Column(Integer)

    def * = (code, otype, date, modify, approve, status, send, result, fid)
      .<>((MesStockOrdersRec.apply _).tupled, MesStockOrdersRec.unapply)
  }

}
